const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const fs = require('fs')
const path = require('path');
const db = require('../models/db');
const api_form = require('../router/api.form');
const api_upload = require('../router/api.upload')
var Logger = require('./logger');
const logger = Logger.GetLogger('app')
logger.info('app加载成功...')

const PORT = process.env.PORT || '5168';
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json());

// 上传图片静态地址
app.use('/uploads',express.static('./src/uploads'))
// 关于form的先关操作
app.use('/api/upload', api_upload)
app.use('/api/form', api_form)
app.use('/api/navsidelist', (req, res) => {
  let reqPath = path.join(__dirname, '../mock/mock.json');
  fs.readFile(reqPath,'utf8', (err, doc) => {
    if (doc) {
      res.json({data:JSON.parse(doc),code:0,message: '数据查询成功....'})
    }
  })
})

app.listen(PORT, () => {
  console.log(`server is runing ${PORT}`);
})